/**
 * 
 */
package peer;


import java.util.ArrayList;
import java.util.TimerTask;

import peer.SharingManager.FileReference;
import peer.SharingManager.SharingManager;
import peer.gui.PeerGUI;

/**
 * @author Andrew Nicholson
 *
 */
public class UpdateSharedFilesTask extends TimerTask {

	private SharingManager sharingManager;
	private PeerGUI peerGUI;
	private ArrayList<FileReference> previousList;
	
	public UpdateSharedFilesTask(SharingManager sharer, PeerGUI ui)
	{
		sharingManager = sharer;
		peerGUI = ui;
		previousList = new ArrayList<FileReference>();
	}
	
	/* (non-Javadoc)
	 * @see java.util.TimerTask#run()
	 */
	@Override
	public void run()
	{
		ArrayList<FileReference> files = sharingManager.findMatches(".+");
		for (FileReference f: files)
		{
			if(!previousList.contains(f))
			{
				previousList.add(f);
				peerGUI.addFileToLibrary(f);
			}
		}
		
	}

}
